﻿#include "u_quality_page.h"

QualityPage::QualityPage(QWidget *parent) : MyDialog(parent)
{
    this->InitWidget();
    this->SetupConnections();

    this->setTitle("历史功率");
    this->resize(1000, 600);
}

void QualityPage::InitWidget(){
    btnQuery  = new QPushButton(QChar(0xe639) + QString(" 查询"));

    QList<Equipment> equList = globalData->sqlBase->GetEquipmentList();
    editEquCode = new QComboBox();
    for(int i = 0; i<equList.size(); i++){
        Equipment equ = equList.at(i);
        editEquCode->addItem(equ.devname);
    }

    editStartTime   = new QDateTimeEdit();  editStartTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss"); editStartTime->setCalendarPopup(true);/*弹出日历窗口，当存在有效的日期显示格式时，此属性才有效。*/  editStartTime->setDateTime(QDateTime::currentDateTime().addSecs(-2*3600));//比当前时间早7.2秒
    editEndTime     = new QDateTimeEdit();    editEndTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss"); editEndTime->setCalendarPopup(true);   editEndTime->setDateTime(QDateTime::currentDateTime());

    chart = new QualityHistoryChart();
    chart->setMinimumHeight(250);

    QHBoxLayout *btnLayout = new QHBoxLayout();
    btnLayout->addWidget(new QLabel("设备:"));
    btnLayout->addWidget(editEquCode);
    btnLayout->addWidget(new QLabel("开始时间:"));
    btnLayout->addWidget(editStartTime);
    btnLayout->addWidget(new QLabel("结束时间:"));
    btnLayout->addWidget(editEndTime);
    btnLayout->addStretch();
    btnLayout->addWidget(btnQuery);

    QGroupBox *groupbox11 = new QGroupBox();
    groupbox11->setStyleSheet("margin-top: 0px;");
    groupbox11->setLayout(btnLayout);

    //-------------------------------------------------

    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->setMargin(0);
    mainLayout->setSpacing(10);
    mainLayout->addWidget(groupbox11);
    mainLayout->addWidget(chart);
    this->addLayout(mainLayout);
}

void QualityPage::SetupConnections(){
    connect(btnQuery , SIGNAL(clicked()), this, SLOT(OnBtnQueryClicked()));
}

void QualityPage::Initialize(){

    QString name=editEquCode->currentText();
    QDateTime tr=editStartTime->dateTime();
    QDateTime et=editEndTime->dateTime();

    qualityList =globalData->sqlBase->GetSimList(name,tr,et);
    chart->SetData(qualityList);
}

void QualityPage::OnBtnQueryClicked(){
    this->Initialize();
}
